package com.besttone.action;

import com.besttone.bean.ReportBean;
import com.besttone.util.Encryption;
import com.besttone.util.HttpClientUtil;
import com.besttone.util.PropertieUtils;
import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhengzhenzhen on 2017/7/19.
 * 商家中心按月报表统计中转封装:
 * http://localhost:9090/signalAndsms_2_solr/busiCenter?month_id=2017-06
 */
public class BusinessCenterAction extends Controller {
    private static Log _log = LogFactory.getLog(BusinessCenterAction.class);
    public void index(){
        String sp_account = getPara("sp_account");
        String sp_pwd = getPara("sp_pwd");
        String month_id=getPara("month_id");
        Date nowDate = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateStr = formatter.format(nowDate);
        ReportBean bean = new ReportBean();
        bean.setReportTime(month_id);
        Map<String, String> params = new HashMap<String, String>();
        params.put("infos", JsonKit.toJson(bean));
        params.put("name", PropertieUtils.getProperty("request_name"));
        params.put("timestamp", dateStr);
        params.put("sign", Encryption.getRequestStr(dateStr));
        HttpClientUtil.HttpClientResult reqResult = HttpClientUtil.httpClientOfPost(
                "http://180.153.43.242:6320/JMInterface/http/reportInterface/report", params);
        String jsonStr = reqResult.getValue();
        if (jsonStr != null) {
            System.out.println(jsonStr);
        }
        setAttr("result_msg",jsonStr);
        renderJson();
        return;
    }
}
